package logic

import (
	"context"
	"errors"
	"novel-start/models/mysql"

	"novel-start/novelrpc/internal/svc"
	"novel-start/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookShelfListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookShelfListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookShelfListLogic {
	return &BookShelfListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookShelfListLogic) BookShelfList(in *novelrpc.BookShelfListRequest) (*novelrpc.BookShelfListResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User

	if err := user.FindUserById(mysql.DB, in.UserId); err != nil {
		return nil, errors.New("用户不存在")
	}

	var bookShelfList []*novelrpc.BookShelfList

	bookShelfList = mysql.BookShelfList(mysql.DB, in, bookShelfList)

	return &novelrpc.BookShelfListResponse{
		List: bookShelfList,
	}, nil
}
